package com.ocom.human.controller;

import com.ocom.common.constant.HumanServiceUrl;
import com.ocom.common.entity.human.EntityResourceApi;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.ResultUtil;
import com.ocom.human.service.ResourceApiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class ResourceApiController {


    @Autowired
    private ResourceApiService resourceApiService;

    @GetMapping(HumanServiceUrl.URLP_getWebPageList)
    public Result webPageList(@RequestParam(required = false ,defaultValue = "0") Integer parentId){
        List<EntityResourceApi> list=resourceApiService.selectList(parentId);
        List<Map<String,Object>> resourceApiList=new ArrayList<>();
        for (EntityResourceApi entityResourceApi : list) {
            Map<String,Object> map=new HashMap<>();
            map.put("pageId",entityResourceApi.getId());
            map.put("pageCode",entityResourceApi.getApiCode());
            map.put("pageName",entityResourceApi.getApiName());
            map.put("description",entityResourceApi.getDescription());
            map.put("pageAppCode",entityResourceApi.getPageAppCode());
            map.put("parentId",entityResourceApi.getParentId());
            resourceApiList.add(map);
        }
        Map<String,Object> reMap=new HashMap<>();
        reMap.put("pageList",resourceApiList);
        return ResultUtil.success(reMap);
    }
}
